//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.mblog.api.oauth.util;

import com.alibaba.fastjson.JSONObject;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang3.RandomStringUtils;

public class TokenUtil {
    private static final String STR_S = "abcdefghijklmnopqrstuvwxyz0123456789";

    public TokenUtil() {
    }

    public static String getAccessToken(String string) {
        String accessToken = "";

        try {
            JSONObject json = JSONObject.parseObject(string);
            if(json != null) {
                accessToken = json.getString("access_token");
            }
        } catch (Exception var5) {
            Matcher m = Pattern.compile("^access_token=(\\w+)&expires_in=(\\w+)&refresh_token=(\\w+)$").matcher(string);
            if(m.find()) {
                accessToken = m.group(1);
            } else {
                Matcher m2 = Pattern.compile("^access_token=(\\w+)&expires_in=(\\w+)$").matcher(string);
                if(m2.find()) {
                    accessToken = m2.group(1);
                }
            }
        }

        return accessToken;
    }

    public static String getOpenId(String string) {
        String openid = null;
        Matcher m = Pattern.compile("\"openid\"\\s*:\\s*\"(\\w+)\"").matcher(string);
        if(m.find()) {
            openid = m.group(1);
        }

        return openid;
    }

    public static String getUid(String string) {
        JSONObject json = JSONObject.parseObject(string);
        return json.getString("uid");
    }

    public static String randomState() {
        return RandomStringUtils.random(24, "abcdefghijklmnopqrstuvwxyz0123456789");
    }
}
